#include"BalanceTree.h"
#include <iostream>

using namespace std;
static int arr[] = { 1,5,4,3,2,6 };
#define TBL_SIZE(a) ( (sizeof(a)) / (sizeof(a[0])) )

	int main()
	{
		AvlTree<int> bt;
		vector<int> data;
		data.push_back(1);
		data.push_back(2);
		data.push_back(3);
		data.push_back(4);
		data.push_back(5);
		data.push_back(6);
		data.push_back(7);
		data.push_back(8);
		BST_sort(data, bt);
		cout<<"平衡后Avl树的详细信息："<<endl;
		bt.levels_show();//层次遍历，显示插入后的AvlTree
		cout << "中序遍历输出data：" << endl;
		for (int i = 0; i < 8; i++) {
			data[i] = bt.findMin();
			cout << data[i] << " ";
			bt.remove(bt.findMin());
		}
		//删除二叉树
		while (bt.root != nullptr) {
			bt.remove(bt.findMin());
		}
		cout << endl;
		cout << "-----------------" << endl;
        int i, ilen;
        SplayTree<int>* tree = new SplayTree<int>();

        cout << "依次添加: ";
        ilen = TBL_SIZE(arr);
        for (i = 0; i < ilen; i++)
        {
            cout << arr[i] << " ";
            tree->insert(arr[i]);
        }
		cout << endl;
        cout << "Splay树的详细信息: " << endl;
        tree->levels_show();
		cout << endl;
        i = 3;
        cout << "旋转节点使" << i << "为根节点";
        tree->splay(i);
		cout << endl;
        cout << "Splay树的详细信息: " << endl;
        tree->levels_show();

        tree->destroy();

        return 0;
	}
